/**
 * Copyright (C), 2020-2021
 * FileName: PurseService
 * Author:   86189
 * Date:     2021/3/8 23:09
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.itheima.wallet.web.service;

import com.itheima.user.pojo.User;
import com.itheima.wallet.api.PayApi;
import com.itheima.wallet.pojo.Account;
import com.itheima.wallet.pojo.Trade;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author 86189
 * @create 2021/3/8
 * @since 1.0.0
 */
@Service
public class PurseService {

    @Autowired
    private DecodeService decodeService;

    @Reference(version = "1.0.0")
    private PayApi payApi;

    public Boolean chongzhi(String token, Double money) {
        User user = decodeService.queryUserByToken(token);
        if (user ==null){
            return null;
        }

        Boolean b = payApi.pay(user.getAccountId(), money);

        return b;
    }

    public Boolean tixian(String token, Double money) {
        User user = decodeService.queryUserByToken(token);
        if (user ==null){
            return null;
        }

        Boolean b = payApi.reduce(user.getAccountId(), money);

        return b;
    }


    public List<Trade> selecttrade(String token) {
        User user = decodeService.queryUserByToken(token);
        if (user ==null){
            return null;
        }

        List<Trade> tradeList = payApi.listTrade(user.getAccountId());

        return tradeList;
    }

    public Account selectaccount(String token) {
        User user = decodeService.queryUserByToken(token);
        if (user ==null){
            return null;
        }

        Account account = payApi.listAccount(user.getAccountId());

        return account;
    }
}
